const map = {
  '2': 'abc',
  '3': 'def',
  '4': 'ghi',
  '5': 'jkl',
  '6': 'mno',
  '7': 'pqrs',
  '8': 'tuv',
  '9': 'wxyz',
}

var letterCombinations = function(digits) {
  const ans = [], path = [];
  if (digits.length === 0) return ans;
  backtracking(0, ans, path, digits);
  return ans;
};

function backtracking(startIndex, ans, path, digits) {
  if (path.length === digits.length) {
    ans.push([...path].join(""));
    return;
  }

  const zimu = map[digits[startIndex]];

  for (let i = 0; i < zimu.length; i++) {
    path.push(zimu[i]);
    backtracking(startIndex+1, ans, path, digits);
    path.pop();
  }
}

const digits = "5";
console.log(letterCombinations(digits))